package com.yaoli.niuke;

import java.util.*;
import java.util.Scanner;

public class _021_Test{
    public static void main(String [] args){
        getZhi();
        Scanner input = new Scanner(System.in);
        int a = input.nextInt();
        int b = input.nextInt();


        int count = 0;
        for(int i = a ; i <= b ; i++){

            char[] tmp = String.valueOf(i).toCharArray();

            boolean flag = false;

            for(int j = 0 ; j < tmp.length ; j++){
                boolean flag2 = false;
                for(int k = j + 1 ; k < tmp.length ; k++){
                    String q = String.valueOf(tmp[j]);
                    String p = String.valueOf(tmp[k]);

                    if(sets.contains(q+p) || sets.contains(p+q)){
                        flag = true;
                        flag2 = true;
                        break;
                    }
                }

                if(flag2 == true){
                    break;
                }
            }

            if(flag == true){
                count++;
            }

        }

        System.out.println(count);

    }

    public static Set<String> sets = new HashSet<String>();

    public static void getZhi(){
        for(int i = 2; i <= 99 ; i = i + 1){
            boolean is = true;
            for(int j = 2; j <= Math.sqrt(i) ; j++){
                if( i % j == 0){
                    is = false;
                    break;
                }
            }
            if(is==true){
                //System.out.println(String.valueOf(i));
                sets.add(String.valueOf(i));
            }
        }
        sets.add("2");
    }
}